<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="img/touxiang.png" alt="">
        <span class="title">随心日记系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>
        <a href="blog_list.html">主页</a>
        <a href="blog_edit.html">写日记</a>
        <a href="reg.html">注册</a>
        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的登陆框 -->
        <from class="login-dialog">
        <!--<div >-->
            <!--<h3>登陆</h3>-->
            <div class="row">
                <!--<span>用户名</span>-->
                <input type="text" id="username" placeholder="输入你的账号">
            </div>
            <div class="row">
                <!--<span>密码</span>-->
                <input type="password" id="password" placeholder="输入你的密码    ">
            </div>
            <!-- 协议栏 -->
            <div class="agreement">
                <input type="radio" id="agree" ></input>
                <label for="agree">已阅读并同意服务协议与博客系统隐私指引</label>
            </div>
            <div class="row">
                <button id="submit" onclick="doLogin()">登录</button>
            </div>
            <!-- 更多选项 -->
            <div class="more">
                <a>扫码登录</a>
                <a>更多选项</a>
<!--                <span>扫码登录</span>
                <span>更多选项</span>-->
            </div>
       <!-- </div>-->
        </from>
    </div>
    <script>
        // 登录功能
        function doLogin() {
            // 1.非空校验
            var username = jQuery("#username");
            var password = jQuery("#password");
            if(username.val().trim() == "") {
                alert("请先输入用户名!")
                username.focus();
                return false;
            }
            if(password.val().trim() == "") {
                alert("请输入密码！")
                password.focus();
                return false;
            }
            // 2.将数据提交到后端
            jQuery.ajax({
                url:"/user/login",
                type:"GET",
                data:{
                    "username":username.val(),
                    "password":password.val()
                },
                success:function(ret) {
                    //3.将结果展示给用户
                    if (ret.code == 200 && ret.data == 1 ) {
                        alert("登录成功!");
                        location.href = "myblog_list.html";
                    } else {
                        alert("登录失败!"+ret.msg);
                    }
                }
            });
        }
    </script>
</body>

</html>